const path = require('path')
const express = require('express')
const app = express()
const multer = require('multer')

const storage = multer.diskStorage({
  destination: (req, file, cb) => {
    cb(null, './upload/')
  },
  filename:(req, file, cb) =>{
    cb(null, Date.now() + path.extname(file.originalname))
  }
})
const upload = multer({
  // dest:'./upload/'
  storage
})

app.post('/login',upload.any(), (req, res, next) => {
  res.end('登陆成功')
})

app.post('/upload', upload.single('file'), (req, res, next) => {
  console.log(req.file)
  res.end('文件上传成功')
})

app.listen(8000, () => {
  console.log('服务器启动成功')
})